package org.example.bussiness;

import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.Nullable;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * @author hsj
 * @description:
 * @date 2023/2/15 15:05
 */
public class Func {
    public static String[] toStrArray(String str) {
        return toStrArray(",", str);
    }

    public static String[] toStrArray(String split, String str) {
        return StringUtils.isBlank(str) ? new String[0] : str.split(split);
    }
    public static List<String> toStrList(String str) {
        return Arrays.asList(toStrArray(str));
    }
    public static List<Long> toLongList(String str) {
        return Arrays.asList(toLongArray(str));
    }
    public static Long[] toLongArray(String str) {
        return toLongArray(",", str);
    }
    public static Long[] toLongArray(String split, String str) {
        if (StringUtils.isBlank(str)) {
            return new Long[0];
        } else {
            String[] arr = str.split(split);
            Long[] longs = new Long[arr.length];

            for(int i = 0; i < arr.length; ++i) {
                Long v = toLong(arr[i], 0L);
                longs[i] = v;
            }

            return longs;
        }
    }
    public static long toLong(@Nullable final Object str, final long defaultValue) {
        return toLong(String.valueOf(str), defaultValue);
    }
    public static long toLong(@Nullable final String str, final long defaultValue) {
        if (str == null) {
            return defaultValue;
        } else {
            try {
                return Long.valueOf(str);
            } catch (NumberFormatException var4) {
                return defaultValue;
            }
        }
    }
    public static String join(Collection<?> coll) {
        return StringUtils.join(coll);
    }

    public static String join(Collection<?> coll, String delim) {
        return StringUtils.join(coll, delim);
    }

    public static String join(Object[] arr) {
        return StringUtils.join(arr);
    }

    public static String join(Object[] arr, String delim) {
        return StringUtils.join(arr, delim);
    }

}
